package us.wili.dev.common.util.netease.exception;

/**
 * Created by JasonY on 17/4/22.
 */
public enum NeteaseCodeEnum {

    UNDEFINED(0, "未定义"),

    OK(200, "操作成功"),
    INCORRECT_VERSION_SDK(201, "客户端版本不对，需升级sdk"),
    BLOCK(301, "被封禁"),
    INCORRECT_PASSWORD(302, "用户名或密码错误"),
    IP_LIMIT(315, "IP限制"),
    INVALID_OPERATION(403, "非法操作或没有权限"),
    OBJECT_UNFOUND(404, "对象不存在"),
    PARAM_TOO_LONG(405, "参数长度过长"),
    READ_ONLY(406, "对象只读"),
    CLIENT_REQUEST_TIMEOUT(408, "客户端请求超时"),
    AUTHENTICATION_FAILED(413, "验证失败(短信服务)"),
    INVALID_PARAMS(414, "参数错误"),
    CLIENT_NETWORK_ERROR(415, "客户端网络问题"),
    FREQUENCY_CONTROL(416, "频率控制"),
    REPETITIVE_OPERATION(417, "重复操作"),
    CHANNEL_UNAVAILABLE(418, "通道不可用(短信服务)"),
    NUM_OVER_LIMIT(419, "数量超过上限"),
    ACCOUNT_BLOCK(422, "账号被禁用"),
    HTTP_REPETITIVE_REQUEST(431, "HTTP重复请求"),
    SERVER_INNER_ERROR(500, "服务器内部错误"),
    SERVER_BUSY(503, "服务器繁忙"),
    MESSAGE_WITHDRAW_OVERTIME(508, "消息撤回时间超限"),
    INVALID_PROTOCOL(509, "无效协议"),
    SERVICE_UNAVAILABLE(514, "服务不可用"),
    UNPACK_FAIL(998, "解包错误"),
    PACK_FAIL(999, "打包错误"),

    TEAM_USER_UPPER_LIMIT(801, "人数达到上限"),
    TEAM_PERMISSION_DENY(802, "没有权限"),
    TEAM_NOT_FOUND(803, "群不存在"),
    TEAM_USER_NOT_IN(804, "用户不在群"),
    TEAM_MISMATCH_TYPE(805, "群类型不匹配"),
    TEAM_UPER_LIMIT(806, "创建群数量达到限制"),
    TEAM_USER_STATUS_ERROR(807, "群成员状态错误"),
    TEAM_APPLICATION_APPROVED(808, "申请成功"),
    TEAM_USER_ALREADY_IN(809, "已经在群内"),
    TEAM_INVITATION_AGREED(810, "邀请成功"),
    ;

    public static NeteaseCodeEnum get(int code) {
        switch (code) {
            case 200: return OK;
            case 201: return INCORRECT_VERSION_SDK;
            case 301: return BLOCK;
            case 302: return INCORRECT_PASSWORD;
            case 315: return IP_LIMIT;
            case 403: return INVALID_OPERATION;
            case 404: return OBJECT_UNFOUND;
            case 405: return PARAM_TOO_LONG;
            case 406: return READ_ONLY;
            case 408: return CLIENT_REQUEST_TIMEOUT;
            case 413: return AUTHENTICATION_FAILED;
            case 414: return INVALID_PARAMS;
            case 415: return CLIENT_NETWORK_ERROR;
            case 416: return FREQUENCY_CONTROL;
            case 417: return REPETITIVE_OPERATION;
            case 418: return CHANNEL_UNAVAILABLE;
            case 419: return NUM_OVER_LIMIT;
            case 422: return ACCOUNT_BLOCK;
            case 431: return HTTP_REPETITIVE_REQUEST;
            case 500: return SERVER_INNER_ERROR;
            case 503: return SERVER_BUSY;
            case 508: return MESSAGE_WITHDRAW_OVERTIME;
            case 509: return INVALID_PROTOCOL;
            case 514: return SERVICE_UNAVAILABLE;
            case 998: return UNPACK_FAIL;
            case 999: return PACK_FAIL;
            case 801: return TEAM_USER_UPPER_LIMIT;
            case 802: return TEAM_PERMISSION_DENY;
            case 803: return TEAM_NOT_FOUND;
            case 804: return TEAM_USER_NOT_IN;
            case 805: return TEAM_MISMATCH_TYPE;
            case 806: return TEAM_UPER_LIMIT;
            case 807: return TEAM_USER_STATUS_ERROR;
            case 808: return TEAM_APPLICATION_APPROVED;
            case 809: return TEAM_USER_ALREADY_IN;
            case 810: return TEAM_INVITATION_AGREED;
            default: return UNDEFINED;
        }
    }

    private Integer code;
    private String message;

    private NeteaseCodeEnum(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    public Integer getCode() {
        return code;
    }

    public String getMessage() {
        return message;
    }
}
